@import "../components/link.less";
@import "../components/inputs.less";
@import "../components/messages.less";
@import "../components/popups.less";
@import "../components/dropdown";
@import "../components/progress";
@import "../components/context-input";
@import "../components/badge";
@import "../components/rehost-slider.less";
@import "../components/hover-swapper.less";

// builtin pages components
@import "./components/tooltip.less";
@import "./components/notice-banner.less";
@import "./components/files-browser.less";
@import "./components/diff";
@import "./components/favicon-picker";
@import "./components/archive-select-btn";
@import "./components/archive-comparison";
@import "./components/revision-indicator.less";
@import "./components/file-editor.less";
@import "./components/create-archive-popup.less";
@import "./components/opaque-binary.less";

.window-content.builtin.library {
  // position relative so that popups stay in place
  position: relative;
}

.drag-hint {
  box-sizing: border-box;
  display: none;
  position: absolute;
  top: 0;
  left: 0;
  z-index: 3;
  width: 100%;
  height: 100%;
  padding: 20px;
  padding-top: 30vh;
  background: fadeout(tint(mix(@blue, @teal), 92%), 5%);
  color: rgba(0,0,0,.5);
  color: @color-text--muted;
  text-align: center;

  &:before {
    display: block;
    content: '';
    position: absolute;
    left: 15px;
    top: 15px;
    width: ~"calc(100% - 30px)";
    height: ~"calc(100% - 30px)";
    border: 5px dashed rgba(0,0,0,.15);
  }

  .icons {
    &:extend(.flex);
    justify-content: center;
    align-items: center;
    margin-bottom: 15px;

    .fa {
      font-size: 34px;

      &:nth-child(2),
      &:nth-child(4) {
        font-size: 40px;
      }

      &:nth-of-type(3) {
        font-size: 48px;
      }

      &:not(:last-child) {
        margin-right: 10px;
      }
    }
  }

  h1 {
    font-size: 1.5rem;
    font-weight: 500;
  }

  p {
    margin: 0;
    font-size: .9rem;
  }
}

body.drag {

  .drag-hint {
    display: block;
  }
}

.builtin-wrapper.library {

  @media (min-width: 1050px) {
    .builtin-main {
      max-width: none;
      margin: 0 100px 0 200px;
    }
  }

  // column sizings
  .ll-row.archive,
  .ll-column-headings {

    .title {
      flex: 3;
      max-width: none;
    }

    .peers,
    .size {
      min-width: 60px;
      flex: 0.75;
    }

    .date {
      min-width: 120px;
      flex: 0.9;
    }

    .buttons {
      width: 45px;
    }
  }

  .ll-column-headings {
    padding: 0 20px 10px;
  }

  .ll-row.archive {
    height: 50px;
    padding: 0 20px;

    &.menu-open,
    &:hover {

      .buttons,
      .btn,
      .btn.trash,
      .btn.restore {
        opacity: 1;
      }
    }

    .title {
      font-size: 13.5px;

      &.empty {
        overflow: initial;
      }
    }

    .url,
    .peers,
    .date,
    .size {
      font-weight: 300;
      font-size: 12.5px;
      color: @color-text--muted;
    }

    .url {
      margin-right: 0;
    }

    .buttons {
      opacity: 1;

      .trash,
      .restore {
        margin-right: 4px;
        opacity: 0;
      }
    }

    .dropdown-items {
      width: 185px;
      right: -8px;
    }
  }
}

// beaker://library/{datHash} view
.builtin-wrapper.library-view {

  .view {
    background: #f7f7f7;
    margin-bottom: 20px;
  }

  .view-wrapper {
    width: 100%;
    padding: 20px 0;
    margin-bottom: 0;
  }

  .builtin-main {
    max-width: 100%;
    padding: 0;
    height: 100vh;
    overflow-y: auto;
  }

  .container {
    max-width: 800px;
    margin: auto;
    padding: 0 20px;

    @media (min-width: 800px) {
      padding: 0;
    }
  }

  .view {
    max-width: 100%;
    padding: 0;
    font-size: .85rem;

    &.settings,
    &.network {
      background: #fff;
      padding: 15px 20px;
      border: 1px solid #ddd;

      h1 {
        margin-bottom: 20px;
        padding-bottom: 15px;
        border-bottom: 1px solid #eee;
        text-align: center;
        font-size: 1rem;
        font-weight: 500;
      }

      hr {
        margin: 20px 0;
      }
    }

    .section {

      &:not(:last-child) {
        margin-bottom: 40px;
      }
    }
  }

  .back-link {
    margin: 0 0 10px 0;
  }

  .file-view-header {
    &:extend(.flex);
    align-items: center;
    height: 45px;
    border: 1px solid #ddd;
    padding: 0 10px;
    background: #fff;

    .path {
      &:extend(.overflow-ellipsis);
      max-width: 250px;
    }

    a {
      color: initial;

      &:hover {
        text-decoration: none;
      }
    }
  }

  .file-view-container {

    .file-view-header,
    .file-editor-controls {
      &:extend(.flex);
      align-items: center;
      padding: 0 15px;
      border: 1px solid #ddd;

      .actions {
        margin-left: auto;
      }
    }

    .file-editor-controls {
      height: 35px;
      border-top: 0;
      background: #fafafa;

      .editor-options {

        select {
          border: 1px solid #ddd;
          background: #fff;
          height: 24px;
        }
      }
    }

    .file-view-header {
      height: 50px;
    }

    .file-view {
      position: relative;
      border: 1px solid #ddd;
      border-top: 0;
      border-radius: 0 0 2px 2px;

      &.text {
        &:extend(.code-font);
        padding: 5px 15px;
        padding-left: 45px;
        overflow-x: auto;

        .text {
          white-space: pre;
          user-select: initial
        }
      }

      &.media {
        text-align: center;
        background: #ddd;
        padding: 30px 0;

        &.binary {
          background: #fff;
        }

        img {
          border: 1px solid #fff;
          background-color: #fff;
          background-size: 10px 10px;
          background-position: 0 0, 5px 5px;
          background-image:
            linear-gradient(45deg, #ddd 25%, transparent 25%, transparent 75%, #ddd 75%, #ddd),
            linear-gradient(45deg, #ddd 25%, transparent 25%, transparent 75%, #ddd 75%, #ddd);
        }

        video,
        img,
        audio {
          max-width: 550px;
          max-height: 500px;
          margin: auto;
        }

        video,
        img {
          width: auto;
          height: auto;
        }
      }
    }

    .ace-editor {
      height: ~"calc(100vh - 260px)";
      border: 1px solid #ddd;
      border-top: 0;
      border-radius: 0 0 2px 2px;
      background: #fff;

      input {
        height: initial;
      }
    }
  }

  .view.files {

    .hint {
      padding: 20px;
      background: #fff;
      border: 1px solid #ddd;
      margin-top: 20px;
      max-width: 100%;
    }
  }

  .view.network {

    .toggle {
      display: inline-flex;
      .text {
        margin: 0 10px;
      }
    }

    .big-stats {
      display: flex;
      margin: 0 auto 10px;
      max-width: 450px;

      & > div {
        flex: 1;
        text-align: center;
        font-size: 27px;

        span {
          font-size: 15px;
        }
      }
    }

    .small-stats {
      display: flex;

      & > div {
        margin-right: 20px;

        span {
          font-size: 11px;
          text-transform: uppercase;
          color: rgba(0,0,0,0.5);
        }
      }
    }

    .download-status {
      &:extend(.flex);
      align-items: center;
      flex-wrap: nowrap;
      margin-bottom: 20px;

      .btn {
        margin-left: 2px;

        &:focus {
          border: 0;
          box-shadow: none;
        }
      }
    }

    svg.peer-history-graph {
      position: relative;
      margin: 5px 0;

      text {
        fill: @color-text--muted;
        font-size: .8rem;
        font-weight: 500;
      }
    }

    .seed-controls {
      display: flex;
      height: 20px;

      .seed-toggle {
        height: 20px;

        .toggle {
          margin-bottom: 0;
        }
      }

      .seed-slider {
        margin-left: 10px;
        padding-left: 24px;
        border-left: 1px solid #ccc;

        input {
          height: 24px;
        }
      }

      .seed-time-label {
        margin-left: 15px;

        .fa-circle {
          margin-right: 3px;
          font-size: 12px;

          &.green {
            color: @green;
          }
          &.yellow {
            color: @yellow;
          }
          &.red {
            color: @red;
          }
        }
      }

      .hint {
        padding-left: 20px;
        border-left: 1px solid #ccc;
        margin: 0 10px;
      }
    }
  }

  .view.settings {

    .toggleable-container {
      display: inline-block;
    }

    .favicon {
      width: 32px;
      height: 32px;
    }

    .favicon-picker-btn {
      cursor: pointer;
      border: 1px solid transparent;

      &:hover,
      &.pressed {
        border-color: #ccc;
        background: #eee;
      }
    }

    .favicon-picker {
      padding: 10px;
    }

    .toggle .switch {
      margin-right: 10px;
    }

    .input-group.sync-path {
      position: relative;
      flex-wrap: wrap;

      input[type="text"] {
        border-radius: 4px 0 0 4px;
        flex: ~"calc(100% - 100px)";
        margin-top: 10px;
        margin-left: 20px;

        @media (min-width: 800px) {
          flex: 1;
          margin: 0;
        }

        &:focus {
          box-shadow: none;
        }
      }

      .btn {
        border-left: 0;
        border-radius: 0 4px 4px 0;

        &.desktop {
          display: none;

          @media (min-width: 800px) {
            display: block;
          }
        }

        &.desktop {
          width: 190px;
        }

        &.mobile {
          display: block;
          margin-top: 10px;

          @media (min-width: 800px) {
            display: none;
          }
        }
      }
    }

    // TODO
    .git-setup-commands {

      pre {
        &:extend(.code-font);
        padding: 10px;
        font-size: 13px;
        line-height: 1.42857143;
        color: #333;
        background-color: #f5f5f5;
        border-radius: 4px;
      }
    }

    .success-message {
      margin-left: 5px;

      i.fa-check {
        color: shade(@green, 15%);
        -webkit-text-stroke: .3px #fff;
      }
    }
  }

  .library-view-header {
    position: sticky;
    top: 0;
    z-index: 5000;
    background: #fff;
    margin: 0;

    &.expanded {
      top: -60px;

      &.has-description {
        top: -90px;
      }
    }

    .back-link {
      position: absolute;
      left: 10px;
      top: 15px;
      width: 27px;
      text-align: center;
      font-size: 1.2rem;
      color: rgba(0,0,0,.2);
      cursor: pointer;
      border-radius: 4px;
      display: none;
      margin: 0;

      * {
        cursor: pointer;
      }

      @media (min-width: 1050px) {
        display: block;
      }

      &:hover {
        color: @color-text;
        background: #eee;
      }

      @media (max-width: 900px) {
        display: none;
      }
    }

    .info {
      &:extend(.flex);
      align-items: center;
      height: 60px;
      position: relative;
      padding: 20px 0 10px 0;

      .primary-action {
        &:extend(.flex);
        position: absolute;
        top: 20px;
        right: 0;

        & > * {
          margin-left: 5px;
        }

        .btn {
          min-width: 30px;
        }

        .fa {
          &.green {
            color: @green;
          }
          &.yellow {
            color: @yellow;
          }
          &.red {
            color: @red;
          }
        }

        .dropdown.seed {
          .dropdown-items {
            width: 300px;
          }
        }

        .dropdown.share {
          .dropdown-items {
            width: 350px;
          }

          .dropdown-item {
            background: #fff;
            cursor: default;
            padding: 15px;

            p {
              margin-left: 0;
              color: @color-text;
            }
          }

          p.copy-url {
            &:extend(.flex);
            margin-top: 5px;
            margin-bottom: 0;

            input {
              flex: 1;
              font-size: 12px;
              border-color: #eee;
              background: #eee;
              margin-right: 5px;
            }

            .btn.full-width {
              margin-top: 10px;
            }
          }
        }
      }
    }

    .title {
      &:extend(.flex);
      flex-wrap: nowrap;
      align-items: center;
      height: 32px;

      h1,
      input {
        font-size: 1.6rem;
        font-weight: 600;
        line-height: 30px;
      }

      h1 {
        position: relative;
        height: 32px;
        max-width: 500px;
        padding: 0 8px;
        text-overflow: ellipsis;
        overflow: hidden;
        white-space: nowrap;
        text-align: center;
        border: 1px solid transparent;
      }

      input {
        position: relative;
        z-index: 3; // on small screens this hides the primary action buttons
        width: 100%;
        height: 32px;
        max-width: 500px;
        border-radius: 0;
        cursor: auto;
      }

      .favicon {
        height: 32px;
        width: 32px;
        margin: 4px 2px 0 -2px;
      }

      .favicon-picker {
        padding: 10px;
      }

      &.editable {

        h1:hover {
          cursor: text;
          border-color: #ccc;
        }

        .favicon:hover {
          cursor: pointer;
          background: #eee;
        }
      }
    }

    .description {
      height: 23px;
      margin: 7px 0 0;
      white-space: pre;
      overflow: hidden;
      text-overflow: ellipsis;
      font-size: .9rem;
    }
  }

  .library-toolbar {
    width: 100%;
    height: 55px;
    border-bottom: 1px solid #ddd;
    font-size: .9rem;

    .nav-items,
    .container {
      &:extend(.flex);
      align-items: center;
    }

    .buttons {
      &:extend(.flex);
      align-items: center;
      display: none;
      margin-left: auto;

      @media (min-width: 650px) {
        display: flex;
      }

      > .btn {
        color: @color-text;
        margin-right: 0;
      }

      .link {
        font-size: .8rem;
        margin-right: 5px;
      }
    }

    .favicon {
      width: 16px;
      height: 16px;
      margin-right: 10px;
    }

    .middot {
      margin: 0 6px;
    }

    .peer-count {
      font-size: 0.8rem;
    }

    .peer-count,
    .middot {
      color: gray;
    }
  }

  .nav-item {
    &:extend(.flex);
    align-items: center;
    height: 55px;
    margin-right: 40px;

    &.active {
      text-decoration: underline;
    }
  }

  .nav-archive-title {
    display: none;
    margin-right: 35px;
    font-weight: 500;

    &.visible {
      display: flex;
    }

    .favicon {
      margin-right: 5px;
    }
  }

  .nav-links {
    height: 100%;

    .link {
      margin-right: 25px;

      &.active {
        text-decoration: underline;
      }
    }
  }

  .dropdown.menu {
    color: @color-text;

    &.open .btn.primary {
      box-shadow: inset 0px 0 5px rgba(0,0,0,0.25);
    }

    .btn.primary {
      .fa-caret-down {
        font-weight: bold;
      }
    }

    .dropdown-items {
      width: 250px;
      background: #fff;
      font-size: 13px;
    }

    .dropdown-item {
      .fa {
        color: @color-text;
      }

      &.disabled {
        cursor: default;
        color: @color-text--light;

        * {
          color: @color-text--light;
        }

        &:hover {
          background: none;
        }
      }
    }

    .section.menu-items {
      border-bottom: 0;
      padding-bottom: 0;

      &:last-of-type {
        padding-bottom: 5px;

        .dropdown-item:last-of-type {
          border-bottom: 0;
        }
      }
    }

    .buttons {
      &:extend(.flex);
      flex-wrap: nowrap;
      padding: 8px 10px;

      .btn {
        flex: 50%;

        &:last-of-type {
          margin-left: 5px;
        }

        &.full-width {
          margin: 0;
        }
      }
    }
  }

  #library-version-picker {
    display: flex;
    align-items: center;
    margin: 0 0 15px;
    padding: 10px 15px;
    background: #fff;
    border: 1px solid #ddd;

    strong {
      font-weight: 600;
    }

    .revisions-btn {

      .text {
        margin-left: 2px;
      }
    }

    .no-revisions {
      display: none;
      color: rgba(0,0,0,.75);
      margin-right: 10px;

      @media (min-width: 670px) {
        display: block;
      }
    }

    label.toggle {
      margin: 0;

      .switch {
        margin: 0 0 0 10px;
      }
    }

    & > * {
      white-space: nowrap;
    }

    & > .revision-indicator {
      margin-left: 2px;
    }

    .version-picker-ctrl {
      margin-right: 10px;
    }

    .sync-path-btn {
      overflow: hidden;
      text-overflow: ellipsis;
      margin-right: 20px;
    }

    .open-preview-btn,
    .revisions-btn {
      margin-left: 0;
      text-align: center;
    }

    .revisions-btn {
      margin-right: 5px;
    }

    .spacer {
      display: block;
      flex: 1;
    }
  }

  .file-view-container.readme {
    &:extend(.flex);
    flex-wrap: wrap;
    margin-top: 20px;

    .file-view-header,
    .readme {
      width: 100%;
      background: #fff;
    }

    .readme {
      border: 1px solid #ddd;
      border-top: 0;
      border-radius: 0 0 2px 2px;
      padding: 20px;
      font-size: 15px;
      line-height: 1.5;
    }

    .readme.markdown {

      h1,
      h2,
      h3 {
        margin: 15px 0;
        font-weight: 600;
      }

      h1,
      h2 {
        border-bottom: 1px solid #eee;
      }

      h1 {
        font-size: 30px;
      }

      h2 {
        font-size: 24px;
      }

      h3 {
        font-size: 20px;
      }

      ul,
      ol {
        margin-bottom: 15px;
      }

      pre,
      code {
        &:extend(.code-font);
        font-size: 13.5px;
        background: #f0f0f0;
        border-radius: 2px;
      }

      pre {
        padding: 15px;
        border: 0;
      }

      code {
        padding: 3px 5px;
      }

      img {
        max-width: 100%;
      }
    }

    &.plaintext {
      &:extend(.code-font);
      white-space: pre-wrap;
    }
  }

  .hint {
    max-width: 750px;
    margin: 20px auto;
    text-align: center;
    color: rgba(0,0,0,0.8);

    & + .hint {
      border-top: 1px dashed #ddd;
      padding-top: 20px;
    }

    strong {
      font-weight: 600;
    }

    p {
      margin-bottom: 10px;
    }

    h2,
    h3 {
      font-size: inherit;
    }
  }
}

.create-new .dropdown-item {

  .description {
    color: rgba(0,0,0,.55);
    margin-left: 24px;
  }

  &:hover .description {
    color: @color-text;
  }
}

.builtin-wrapper.library-view.readonly .file-view-container .ace-editor {
  height: ~"calc(100vh - 320px)";
}

.revision-header,
.files-browser-header {
  &:extend(.flex);
  align-items: center;
  height: 50px;
  padding: 0 10px;
  background: #fff;
  border: 1px solid #ddd;

  .path {
    &:extend(.overflow-ellipsis);
    max-width: 250px;
    margin-right: 10px;
  }
}